#!usr/bin/python
#-*- coding:utf-8 _*-
"""
@author:root
@file: save_to_mongodb.py
@from kafka save to mongodb url 192.168.10.183:10130
@time: 2018/08/{DAY}
"""

import json
from kafka import KafkaConsumer
from pymongo import MongoClient

consumer = KafkaConsumer('demo.crawled_firehose', bootstrap_servers = ['192.168.10.183'])
#connect to Kafka server and pass the topic we want to consume

client = MongoClient('192.168.10.183',10130)
#client = MongoClient('mongodb://localhost:27017')

db = client.bdata_scrapy
hospital = db.hospital
# hospital_info_data ='''
# '''
for msg in consumer:
    print msg
    # hospital_info_data = dict(msg.value)
    hospital_info = json.loads(msg.value)
    # hospital_info = hospital_info_data
    result = hospital.insert_one(hospital_info)
    print hospital_info
    # print hospital.find_one()
    print result